import numpy as np

def start_file2arrary(file_name):
    #处理数据
    data_file = open(file_name,"r")
    data = data_file.readlines()
    fix_data = []
    for i in data:
        pre_data = []
        #处理\n
        if "\n" in i:
            i.replace("\n","")
        #分割
        i = i.split(",")
        #字符串转数字
        for n in i:
            pre_data.append(np.double(n))
        fix_data.append(pre_data)
    #分离标签与数据
    new_data = [] #[[cen_x,cen_y,],[k,v,s]]
    for one in fix_data:
        new_data.append([one[:40],one[40:]])
    data_file.close()
    return new_data

def start_arrary2train_val(data,train = 0.75):
    #分割数据集-》训练集，测试集
    train_data = []
    val_data = []
    train_number = int(len(data) * train)
    val_number = len(data) - train_number
    print("训练集数量：{}，测试集数量：{}".format(train_number,val_number))
    #获得训练集
    train_data = data[:train_number]
    val_data = data[train_number:]
    return train_data,val_data
def start_data2x_y(data):
    x_data = []
    y_data = []
    for i in data:
        x_data.append(i[0])
        y_data.append(i[1])
    return x_data,y_data
def minmaxscaler(data):
    min = np.amin(data)
    max = np.amax(data)    
    return (data - min)/(max-min)